package com.mycompany.oj.controller;

import com.mycompany.oj.aspect.JudgeLog;
import com.mycompany.oj.entity.JsonResult;
import com.mycompany.oj.entity.QuestionResult;
import com.mycompany.oj.entity.ResultCode;
import com.mycompany.oj.service.Impl.QuestionJudgeServiceImpl;
import com.mycompany.oj.util.SharedService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 *
 * @author asus
 */
@RestController
@Api(tags = "QuestionJudgeController", description = "题库接口")
public class QuestionJudgeController {

    @Autowired
    QuestionJudgeServiceImpl questionjudege;


    private SharedService sharedService = new SharedService();
    //初始化蓝桥杯题库
    @RequestMapping("/init_bank")
    public JsonResult doInitBank(@RequestParam("difficult") String difficult) {
        return new JsonResult(ResultCode.SUCCESS, questionjudege.initQuestionService(difficult));
    }

    //初始化蓝桥杯具体题目
    @RequestMapping("/init_question")
    public JsonResult doInitQuestion(@RequestParam("id") String id) {

        return new JsonResult(ResultCode.SUCCESS, questionjudege.initOneQuestionService(id));
    }

    //初始化课程具体题目
    @RequestMapping("/init_course_question")
    public JsonResult doInitCourseQuestion(@RequestParam("id") String id) {
        return new JsonResult(ResultCode.SUCCESS, questionjudege.getQuestionCourse(id));
    }

    @JudgeLog
    //收藏题目
    @RequestMapping("/favorite")
    public JsonResult doFavorite(@RequestParam("question_id") String question_id, HttpServletRequest request) throws Exception {
        String username = sharedService.getUsername(request);
        questionjudege.favoriteService(username, question_id);
        return new JsonResult(ResultCode.SUCCESS);
    }

    //加载做题结果
    @RequestMapping("/myresult")
    public JsonResult doMyresult(@RequestParam("id") String id) {

        QuestionResult temp = questionjudege.myresultService(id);
        return new JsonResult(ResultCode.SUCCESS, temp);
    }

    //加载答案    
    @RequestMapping("/questionanswer")
    public JsonResult doQuestionAnswer(@RequestParam("question_id") String question_id) {
        return new JsonResult(ResultCode.SUCCESS, questionjudege.questionAnswerService(question_id));
    }

    @RequestMapping("/courseanswer")
    public JsonResult doCourseAnswer(@RequestParam("question_id") String question_id) {
        return new JsonResult(ResultCode.SUCCESS, questionjudege.questionCourseAnswer(question_id));
    }

    //课堂练习 下面一块
    @JudgeLog
    @RequestMapping("/cBank")
    public JsonResult doExperiment(HttpServletRequest request, @RequestParam("kind") String kind) throws Exception {
        String username = sharedService.getUsername(request);
        return new JsonResult(ResultCode.SUCCESS, questionjudege.studentCourseService(username, kind));
    }

    //上次做题历史
    @JudgeLog
    @RequestMapping("/summary")
    public JsonResult doSummary(HttpServletRequest request, @RequestParam("kind") String kind) throws Exception {
        String username = sharedService.getUsername(request);
        return new JsonResult(ResultCode.SUCCESS, questionjudege.summaryService(username, kind));
    }

    @RequestMapping("/summary_t")
    public JsonResult doSummaryT(@RequestParam("schoolid") String schoolid) {
        String username = questionjudege.getShitUsername(schoolid);
        String kind = questionjudege.getLastCourse(username);
        return new JsonResult(ResultCode.SUCCESS, questionjudege.summaryService(username, kind));
    }


}
